import React, { useEffect, Fragment } from 'react';
import { Form, Input, DatePicker, Button, Row, Col } from 'antd';
import { FormContainer, SearchInput, SelectForm } from '@/components/UserForm';
import { getDict } from '@/services/components/userform';
import TimePicker from '@/components/Custom/Time';
import { getemployeebyrole } from '@/services/myRecruit/interview';

const { TextArea } = Input;
const PlanForm = ({
    form,
    user,
    onResetPlan,
    onSavePlan,
    onEdit,
    isEdit,
    dictList,
    pathname,
    getDictData = () => {},
    getLeaderMsg = () => {}
}) => {
    const { getFieldDecorator } = form;

    const { identity = '', disable = '', planDisable = '', name = '' } = dictList;
    const getAdmininterviewLeader = () => {
        let state = true;
        if (pathname === 'admineditinterview') {
            if (!isEdit) {
                state = isEdit;
            }
        }
        return state;
    };
    const Btn1 = () => (
        <Button
            type="primary"
            onClick={() => {
                onEdit();
            }}
        >
            修改
        </Button>
    );
    const Btn2 = () => (
        <div>
            <Button
                style={{ marginTop: 10, marginRight: 10 }}
                onClick={() => {
                    onResetPlan();
                }}
            >
                取消
            </Button>
            <Button
                type="primary"
                style={{ marginTop: 10 }}
                onClick={() => {
                    onSavePlan();
                }}
            >
                保存
            </Button>
        </div>
    );
    const editBtn = () => (isEdit ? Btn1() : Btn2());
    useEffect(() => {}, []);

    return (
        <Fragment>
            <div style={{ display: 'flex', justifyContent: 'space-between' }}>
                <div style={{ marginBottom: 30 }}>
                    <span className="vv-from-title">面试安排</span>
                </div>
                {disable && identity === 'apply' && name === '我发起-修改面试安排' ? editBtn() : ''}
            </div>
            <div className="form-Wrap">
                <FormContainer>
                    <Form.Item label="面试官">
                        {getFieldDecorator('interviewEmployeeId', {
                            rules: [
                                {
                                    required: true,
                                    message: '请选择面试官'
                                }
                            ]
                        })(
                            <SearchInput
                                params={{
                                    companyId: user.companyId,
                                    roleName: '面试官'
                                }}
                                requireParam={['companyId']}
                                getData={params =>
                                    getemployeebyrole(params).then(res => {
                                        if (res && res.code === 10000) {
                                            return res.data || [];
                                        }
                                        return [];
                                    })
                                }
                                selectProps={{
                                    placeholder: '请选择面试官',
                                    allowClear: true,
                                    style: { minWidth: '200px' },
                                    disabled: disable && isEdit && planDisable
                                }}
                                fieldsName={{
                                    value: 'id',
                                    title: 'employeeName',
                                    extraParams: 'employeeName'
                                }}
                            />
                        )}
                    </Form.Item>
                    <Form.Item label="招聘负责人">
                        {getFieldDecorator('interviewLeaderId', {
                            initialValue: dictList.type === 'type0' ? user.id : null,
                            rules: [
                                {
                                    required: true,
                                    message: '请选择招聘负责人'
                                }
                            ]
                        })(
                            <SearchInput
                                params={{
                                    companyId: user.companyId,
                                    roleName: '招聘负责人'
                                }}
                                requireParam={['companyId']}
                                getData={params =>
                                    getemployeebyrole(params).then(res => {
                                        if (res && res.code === 10000) {
                                            getLeaderMsg(res.data);
                                            return res.data || [];
                                        }
                                        return [];
                                    })
                                }
                                selectProps={{
                                    placeholder: '请选择招聘负责人',
                                    allowClear: true,
                                    style: { minWidth: '200px' },
                                    disabled: getAdmininterviewLeader()
                                }}
                                fieldsName={{
                                    value: 'id',
                                    title: 'employeeName',
                                    extraParams: 'employeeName'
                                }}
                            />
                        )}
                    </Form.Item>
                    <Form.Item label="面试类型">
                        {getFieldDecorator('interviewType', {
                            rules: [
                                {
                                    required: true,
                                    message: '请选择面试类型'
                                }
                            ]
                        })(
                            <SelectForm
                                params={{ code: 'interviewType' }}
                                requireParam={['code']}
                                getData={params =>
                                    getDict(params).then(res => {
                                        if (res && res.code === 10000 && res.data) {
                                            return res.data || [];
                                        }
                                        return [];
                                    })
                                }
                                fieldsName={{
                                    selectValue: 'dictValue',
                                    selectTitle: 'dictName'
                                }}
                                // onChange={this.companyChange}
                                selectProps={{
                                    placeholder: '请选择面试类型',
                                    style: { minWidth: 200 },
                                    disabled: disable && isEdit && planDisable
                                }}
                            />
                        )}
                    </Form.Item>
                    <Form.Item label="面试方式">
                        {getFieldDecorator('interviewWay', {
                            rules: [
                                {
                                    required: true,
                                    message: '请选择面试方式'
                                }
                            ]
                        })(
                            <SelectForm
                                params={{ code: 'interviewWay' }}
                                requireParam={['code']}
                                getData={params =>
                                    getDict(params).then(res => {
                                        if (res && res.code === 10000 && res.data) {
                                            getDictData(res.data);
                                            return res.data || [];
                                        }
                                        return [];
                                    })
                                }
                                fieldsName={{
                                    selectValue: 'dictValue',
                                    selectTitle: 'dictName'
                                }}
                                // onChange={this.companyChange}
                                selectProps={{
                                    placeholder: '请选择面试方式',
                                    style: { minWidth: 200 },
                                    disabled: disable && isEdit && planDisable
                                }}
                            />
                        )}
                    </Form.Item>
                    <Form.Item label="面试时间" required>
                        <Row gutter={15}>
                            <Col md={12} xs={24} sm={24}>
                                <Form.Item>
                                    {getFieldDecorator('time', {
                                        rules: [
                                            {
                                                required: true,
                                                message: '请选择面试日期'
                                                // validator(_, value, callback) {
                                                //     if (!value) {
                                                //         callback('请选择面试日期！');
                                                //     } else if (!form.getFieldValue('timeValue')) {
                                                //         callback('请选择面试时间!');
                                                //     } else {
                                                //         console.log(
                                                //             '===============================================>form.getFieldValue',
                                                //             form.getFieldValue('timeValue')
                                                //         );
                                                //         callback();
                                                //     }
                                                // }
                                            }
                                        ]
                                    })(
                                        <DatePicker
                                            allowClear={false}
                                            showTime={false}
                                            format="YYYY-MM-DD"
                                            disabled={disable && isEdit && planDisable}
                                        />
                                    )}
                                </Form.Item>
                            </Col>
                            <Col md={12} xs={24} sm={24}>
                                <Form.Item>
                                    {getFieldDecorator('timeValue', {
                                        rules: [
                                            {
                                                required: true,
                                                message: '请选择时间'
                                            }
                                        ]
                                    })(
                                        <TimePicker
                                            placeholder="请选择时间"
                                            allowClear
                                            disabled={disable && isEdit && planDisable}
                                        />
                                    )}
                                </Form.Item>
                            </Col>
                        </Row>
                    </Form.Item>
                    <Form.Item label="面试地点">
                        {getFieldDecorator('interviewLocation', {
                            rules: [
                                {
                                    min: 2,
                                    max: 50,
                                    message: '请输入2~50个字符'
                                }
                            ]
                        })(<Input placeholder="请输入面试地点" disabled={disable && isEdit && planDisable} />)}
                    </Form.Item>
                    <Form.Item
                        label="面试注意点"
                        vvspan={24}
                        labelCol={{ md: 4 }}
                        wrapperCol={{ md: 20 }}
                        help="2-2000个字符"
                    >
                        {getFieldDecorator('interviewRemark', {
                            rules: [
                                {
                                    min: 2,
                                    max: 2000,
                                    message: '请输入2~2000个字符'
                                }
                            ]
                        })(
                            <TextArea
                                autosize={{ minRows: 3, maxRows: 5 }}
                                disabled={disable && isEdit && planDisable}
                            />
                        )}
                    </Form.Item>
                </FormContainer>
            </div>
        </Fragment>
    );
};
export default PlanForm;
